package com.demo.index;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;


public class AuthInterceptor implements Interceptor {
	public static String CN_NAME = "XM";

    public void intercept(ActionInvocation ai) {

        Controller c = ai.getController();
        String user = c.getSessionAttr(CN_NAME);
        String level="";

//        //过滤微信
//        if(ai.getActionKey().equals("/weixin")) {
//            ai.invoke();
//        }   else {
        if (user != null) {
        	System.out.println("---------------------");
            //如果已经登录过，则直接跳转到主页&& "GET".equalsIgnoreCase(c.getRequest().getMethod().toUpperCase())
            if (ai.getActionKey().equals("/login")) {
                c.render("/index/index.html");
            } else {
                ai.invoke();
                /*}else {
                    c.render("login.html");
                }*/
            }
        } else {
            if (ai.getActionKey().equals("/login") && "POST".equalsIgnoreCase(c.getRequest().getMethod().toUpperCase())) {
                ai.invoke();
            } else {
                c.render("/index/login.html");
            }
        }
    }
//    }
}
